import { ActivatedRoute } from '@angular/router';
import { Component, OnInit } from '@angular/core'
import { Location } from '@angular/common'
import { NewsService } from './service/news.service';

@Component({
    selector: 'app-estate-news-detail',
    templateUrl: './estate-news-detail.component.html',
    styleUrls: ['./estate-news-detail.component.scss']
})
export class EstateNewsDetailComponent implements OnInit {

    news = [];
    activeItem:any;
    index:any;

    public error = false;
    public loading = false;

    constructor(
        private location: Location,
        private service: NewsService,
        private routeInfo: ActivatedRoute,
    ) { }

    ngOnInit() {

        let id = this.routeInfo.snapshot.queryParams['project'];
        this.index = this.routeInfo.snapshot.queryParams['index'];

        this.queryArtcleSummary(id);
    }


    handleReload(){

    }

    onClickLeft() {
        this.location.back()
    }

    //api
    queryArtcleSummary(id) {

        this.loading = true;

        let req = {
            "pager": { "Start": 0, "Limit": 10 },
            "filter": {
                "Lambda": "item=>item.Project==" + id + "&&item.CategoryInfo.Code ==\"ArtcleCategory_News\"",
                "Navigations": [],
                "Latitude": 28.692499,
                "Longitude": 115.815292
            },
            "sorters": [{
                "Property": "item=>item.Id",
                "Direction": "Descending"
            }]
        }

        this.service.queryArtcleSummary(req, res => {
            this.news = res.Result.Value;
            this.activeItem = this.news[this.index]
            this.loading = false;
        });

    }
}
